package server;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.thread.QueuedThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;

public class OTAJettyLauncher {

    private static Logger logger = LoggerFactory.getLogger(OTAJettyLauncher.class);
    private static final int MAX_THREADS = 300;

    public static void main(String[] args) throws Exception {
        StopWatch sw = new StopWatch(ServerInfo.CONTEXT);
        sw.start("OTAJettyLauncher");

        WebAppContext context = new WebAppContext("src/main/webapp", ServerInfo.CONTEXT);
        context.setClassLoader(Thread.currentThread().getContextClassLoader());
        Server server = new Server(ServerInfo.PORT);
        server.addHandler(context);
        server.setStopAtShutdown(true);
        server.setSendServerVersion(true);
        QueuedThreadPool threadPool = new QueuedThreadPool();
        threadPool.setMaxThreads(MAX_THREADS);
        server.setThreadPool(threadPool);
        server.start();

        sw.stop();
        logger.info(sw.prettyPrint());
    }
}
